package com.lvyou.ctrl.mgr;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lvyou.entity.Admin;
import com.lvyou.model.JsonResult;
import com.lvyou.service.AdminLoginSrv;

@RestController
@RequestMapping("/mgr")
public class MgrLoginCtrl {

	@Resource(name="AdminLoginSrv")
	private AdminLoginSrv srv;
	
	@PostMapping("/doLogin")
	public JsonResult doLogin(String username,String password,HttpSession session){
		JsonResult jr=new JsonResult();
		try {
			Map resultMap=srv.doLogin(username, password);
			int code=(Integer)resultMap.get("code");
			if(code==1){
				Admin admin=(Admin)resultMap.get("userInfo");
				admin.setPassword("");
				session.setAttribute("adminInfo", admin);
				jr.setCode(0);
				jr.setData(admin);
			}else{
				jr.setCode(200);
				jr.setMsg("用户不存在或密码错误！");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			jr.setCode(200);
			jr.setMsg("用户不存在或密码错误！");
		}
		return jr;
	}
}
